package com.wyd.resourcetj.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.wyd.resourcetj.dao.IRead_RoomDao;
import com.wyd.resourcetj.model.Read_Room;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * Read_RoomController
 */
@RestController
@RequestMapping(path="/read_room",method = RequestMethod.GET)
public class Read_RoomController {

    @Resource
    private IRead_RoomDao read_RoomDao;

    @ApiOperation(value = "添加资源",notes="添加资源")
	  
    @PostMapping(value = "add")
      
      public Read_Room add(@RequestBody Read_Room r) {
          
          return read_RoomDao.save(r);
          
      }


       @ApiOperation(value = "根据编号删除资源",notes="根据编号删除资源")
      @ApiImplicitParam(name="rid",value ="资源编号",required=true,paramType ="path")
      @DeleteMapping(value ="/{rid}")
        public void del(@PathVariable Integer rid) {

            
            read_RoomDao.deleteById(rid);
             
        
            
        } 
      /*   @ApiOperation(value = "根据编号删除资源",notes="根据编号删除资源")    //逻辑删除
        @ApiImplicitParams({
         @ApiImplicitParam(name="n",value ="0 删除，1 恢复",required=true,paramType ="path"),
        @ApiImplicitParam(name="id",value ="资源编号",required=true,paramType ="path")
        })
        @PutMapping(value = "/{id}/{n}")
          public void del(@PathVariable Integer id,@PathVariable Integer n) {
              
            read_RoomDao.deleteRead_Room(id, n);
               
          
              
          } */

        @ApiOperation(value="根据编号修改资源信息",notes = "根据编号修改资源信息")
        @ApiImplicitParams({
            @ApiImplicitParam(name="rid",value ="资源编号",required=true,paramType ="path"),
            @ApiImplicitParam(name="name",value ="新的资源名",required=true,paramType ="path"),
          
            @ApiImplicitParam(name="remark",value ="备注",required=true,paramType ="path")
            
        })
        @PutMapping(value = "/{rid}/{name}/{remark}")
        public int editRead_Room(@PathVariable Integer rid,@PathVariable String name,@PathVariable String remark) {
            
            return read_RoomDao.editRead_Room(rid,name,remark);
            
        }


        @ApiOperation(value = "查询所有资源",notes = "查询所有资源")
        @PostMapping(value ="/findAll")
      
        public Map findAllRead_Room(){
            
           
          Map<String,Object> map = new HashMap<String, Object>();
		
          List<Read_Room> list =  read_RoomDao.findAll();
          map.put("code", 0);
          map.put("count", list.size());
          map.put("data", list);
          
          
          return map;
        }

        @ApiOperation(value = "根据id查询资源",notes = "根据id查询资源")
        @ApiImplicitParam(name="rid",value ="资源ID",required=true,paramType ="path")
        @PostMapping(value ="/findOne/{rid}")
        public Read_Room findRead_Room(@PathVariable Integer rid){
            
           
             

          Read_Room r=read_RoomDao.findOne(rid);


            return r;
        }

    
}